package com.happyass.show.dao;

import com.happyass.show.entity.Activity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * TODO
 *
 * @author admin
 * @date 2021/1/5 9:52
 *
 * <P></P>
 **/

@Repository
public interface ActivityDao extends PagingAndSortingRepository<Activity,Integer>, JpaRepository<Activity,Integer> {

    Activity findByActivityId(@Param("activityId") Integer activityId);

    Activity findByActivityNameAndActivityDel(@Param("activityName") String activityName, Integer activityDel);

    //自定义sql查询
    @Transactional
    @Modifying(clearAutomatically = true)//修改数据的时候，同时清除实体的数据
    //nativeQuery=true，支持原生sql，nativeQuery=false，支持hql      :userName,对应的是@Param的值
    @Query(value = "select activity_area from activity where activity_addr = :activityAddr",nativeQuery = true)
    Set<String> selectAreaByAddr(@Param("activityAddr") String activityAddr);

    Page<Activity> findByActivityDel(@Param("activityDel") Integer activityDel, Pageable pageable);

    List<Activity> findByActivityDel(@Param("activityDel") Integer activityDel);

    //自定义sql查询
    @Transactional
    @Modifying(clearAutomatically = true)//修改数据的时候，同时清除实体的数据
    //nativeQuery=true，支持原生sql，nativeQuery=false，支持hql      :userName,对应的是@Param的值
    @Query(value = "select activity_area from activity where activity_addr = :activityAddr and not activity_area = :activityArea",nativeQuery = true)
    Set<String> selectAreaByAddrWithoutArea(String activityAddr, String activityArea);


    Page<Activity> findByActivityIdLikeAndActivityDel(@Param("activityId") Integer searchValue, Integer activityDel, Pageable pageable);
    List<Activity> findByActivityIdLikeAndActivityDel(@Param("activityId") Integer searchValue, Integer activityDel);

    Page<Activity> findByActivityNameContainingAndActivityDel(@Param("activityName") String searchValue, Integer activityDel, Pageable pageable);
    List<Activity> findByActivityNameContainingAndActivityDel(@Param("activityName") String searchValue, Integer activityDel);

    Page<Activity> findByActivityAreaContainingAndActivityDel(@Param("activityArea") String searchValue, Integer activityDel, Pageable pageable);
    List<Activity> findByActivityAreaContainingAndActivityDel(@Param("activityArea") String searchValue, Integer activityDel);

    Page<Activity> findByActivityAddrContainingAndActivityDel(@Param("activityAddr") String searchValue, Integer activityDel, Pageable pageable);
    List<Activity> findByActivityAddrContainingAndActivityDel(@Param("activityAddr") String searchValue, Integer activityDel);

    Page<Activity> findByDayTimeLikeAndActivityDel(@Param("dayTime") int parseInt, Integer activityDel, Pageable pageable);
    List<Activity> findByDayTimeLikeAndActivityDel(@Param("dayTime") int parseInt, Integer activityDel);

    Page<Activity> findByActivityStatusLikeAndActivityDel(@Param("activityStatus") int parseInt, Integer activityDel, Pageable pageable);
    List<Activity> findByActivityStatusLikeAndActivityDel(@Param("activityStatus") int parseInt, Integer activityDel);

}
